package com.spsy.pay.lisener;

import com.alibaba.fastjson.JSON;
import com.bw.spsy.vo.NotifyOrderVo;
import com.spsy.order.order.OrderApi;
import com.spsy.pay.domain.PaymentOrder;
import com.spsy.pay.service.IPaymentOrderService;
import com.spsy.pay.vo.OrderMqVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Component;

import java.nio.channels.Channel;

/**
 * @author 沈昕希  &&  (=￣ω￣=)m
 * @Shen "再说错了又能怎么样呢？人生不就是由无数的错误组成的吗"
 * @xin "我是个无聊的人，我有无数的缺点，我也并不喜欢我自己，甚至厌恶我自己"
 * @date 2025/9/23-20:05
 */
@Component
@Slf4j
@RabbitListener(queues = "2302a-a")
public class RabbitLisener {

    @Autowired
    private IPaymentOrderService iPaymentOrderService;

    @Autowired
    private OrderApi orderApi;

    @RabbitHandler
    public void handler(String str) {
        log.info("接收到的信息---str：{}",str);

        try {
            OrderMqVo orderMqVo = JSON.parseObject(str, OrderMqVo.class);

            int i = iPaymentOrderService.updatePaymentOrderByOrderId(PaymentOrder.builder()
                    .orderNo(orderMqVo.getOrderId())
                    .orderStatus(Long.valueOf(orderMqVo.getStatus()))
                    .build());

            NotifyOrderVo orderVo = new NotifyOrderVo();
            orderVo.setOrderId(orderMqVo.getOrderId());
            orderVo.setStatus(2);

            orderApi.createOrder(orderVo);
        }catch (Exception e) {
            log.info("异常:{}",e.getMessage());
        }


    }

}
